package vn.edu.hut.soict.translate.dictionary.pos;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class POSDictionaryReader {

	public POSDictionaryReader() {

	}

	public POSDictionary read(String file) {
		POSDictionary dictionary = new POSDictionary();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
			String line = null;
			while ((line = reader.readLine()) != null) {
				String[] data = line.split(":");
				dictionary.addEntry(data[0].trim(), data[1].trim());
			}
		}
		catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			try {
				if (reader != null) {
					reader.close();
				}
			}
			catch (IOException e) {
				e.printStackTrace();
			}
		}

		return dictionary;
	}
}
